import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter)

//导入视图
import detailsUrl from "@/views/ProductDetail/urls";
import listUrl from "@/views/list/urls";
import loginUrl from "@/views/login/urls";
import registerUrl from "@/views/register/urls";
import orderUrl from "@/views/order/urls";
import basketUrl from "../views/basket/urls"
//import errers from "@/views/errers";


const routes = [
    {path: "/", redirect: "/index"},
    //404路由
]

routes.push(detailsUrl)
routes.push(listUrl)
routes.push(loginUrl)
routes.push(registerUrl)
routes.push(orderUrl)
routes.push(basketUrl)

routes.push({path: "*", component: ()=>import("@/views/errers"), beforeEnter:(to, from, next)=>{
    next()
    } })

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch((err) => err);
};
//创建路由实例
const router = new VueRouter({
    base:"/vue-shop",
    routes,
    mode:"history"  //路由模式
})


//定义全局路由全局守卫
router.beforeEach((to, from, next)=>{
    //console.log(to.path)
    //if (to.path === "/basket" || to.path === "/detail"){
      //  to.meta.Show = false
    //}

    next()

 })
//
// router.beforeResolve((to, from, next)=>{
//     next()
// })
//
// router.afterEach((to, from)=>{
// })


export default router